package com.baofu.paycore.service.processor.account;

import com.baofu.paycore.common.enums.RedisKeyEnum;
import com.baofu.paycore.common.utils.RedisKeyUtil;
import com.baofu.paycore.manager.cache.RedisManager;
import com.baofu.paycore.manager.model.FreezeBO;
import com.baofu.paycore.service.converter.DTO2BOConverter;
import com.baofu.paycore.service.facade.model.AccountFreeze.FreezeDTO;
import com.baofu.paycore.service.facade.model.AccountFreeze.UnfreezeDTO;
import com.baofu.paycore.service.processor.PayBaseProcessor;
import com.system.commons.sequence.redis.SequenceFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <p>
 * </p>
 * User:ames wang  Date: 2017/6/22
 */
@Component
public class UnfreezeProcessor implements PayBaseProcessor<FreezeBO, UnfreezeDTO>{

    /**
     * redis服务
     */
    @Autowired
    private RedisManager redisManager;

    /**
     * 资金明细单号生成
     */
    @Autowired
    private SequenceFacade sequenceFacade;

    /**
     * 支付内部对象构建
     *
     * @param freezeBO  支付模型
     * @param payBaseDTO 请求参数
     */
    @Override
    public PayBaseProcessor process(FreezeBO freezeBO, UnfreezeDTO payBaseDTO) {
        freezeBO.setFreezeNo(sequenceFacade.getUniqueSeq());
        DTO2BOConverter.payBaseBOConverter(payBaseDTO, freezeBO);
        DTO2BOConverter.unfreezeDTOToBO(payBaseDTO, freezeBO);
        getFreezeBO(freezeBO,payBaseDTO);
        return this;
    }

    private void getFreezeBO(FreezeBO unfreezeBO, UnfreezeDTO payBaseDTO) {
        FreezeBO freezeBO=redisManager.queryObjectByKey(RedisKeyUtil.buildRedisKey(RedisKeyEnum.PAY_ACC_UNFREEZE, payBaseDTO.getOrigPayNo()),FreezeBO.class);
        unfreezeBO.setFreezeCode(freezeBO.getFreezeCode());
    }
}
